package com.hong.concurrent.chapter8;

/**
 * @Author csh
 * @Description 多线程设计模式介绍
 * @Date 2018/7/3 21:24
 *
 * Future           ->代表的是未来的一个凭据
 * FutureTask       ->将你的调用逻辑进行了隔离
 * FutureService    ->桥接    Future和FutureTask
 *
 */
public class SyncInvoker {

    public static void main(String[] args) throws InterruptedException {
      /*  String result = get();
        System.out.println(result);*/
      FutureService futureService = new FutureService();
        Future<String> future = futureService.submit(() -> {
            try {
                Thread.sleep(10000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            return "FINISH";
        },System.out::println);
        System.out.println("================");
        System.out.println("do other thing.");
        Thread.sleep(1000);
        System.out.println("================");
        System.out.println(future.get());
    }

    private static String get() throws InterruptedException {
        Thread.sleep(10000);
        return "FINISH";
    }
}
